package jou.cs.support.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import jou.cs.support.enums.ResponseCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R {
    private Integer code;
    @JsonProperty("errMsg")
    private String msg;
    private Object data;

    R(ResponseCode code, Object data) {
        this.data = data;
        this.msg  = code.getMsg();
        this.code = code.getCode();
    }

    public static R then(Object data) {
        return new R(ResponseCode.THEN, data);
    }

    public static R fail() {
        return fail(ResponseCode.FAIL);
    }

    public static R fail(ResponseCode code) {
        return new R(code, null);
    }
}
